package org.hot100_3;

import java.util.HashMap;

public class leetcode1 {
    public static int[] twoSum(int[] nums, int target) {

        int[] res = new int[2];

        HashMap<Integer, Integer> map = new HashMap<>();

        for (int i = 0; i < nums.length; i++) {
            map.put(nums[i], i);
        }

        for (int i = 0; i < nums.length; i++) {
            if (map.containsKey(target - nums[i]) && map.get(target-nums[i])!=i) {
                res[0] = i;
                res[1] = map.get(target - nums[i]);

                return res;
            }
        }

        return res;
    }

    public static void main(String[] args) {
        int [] test ={3,2,4};

        for (int i : twoSum(test, 6)) {
            System.out.println(i);
        }

    }
}
